package com.lanqiao.gxnushop.service;

import com.lanqiao.gxnushop.entity.Address;
import com.lanqiao.gxnushop.mapper.AddressMapper;
import com.lanqiao.gxnushop.util.UUIdUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Schema(description = "地址服务")
@Service
public class AddressService {

    @Autowired
    private AddressMapper addressMapper;
    @Autowired
    private BuyersService buyersService;

    @Schema(description = "增加地址信息")
    public boolean addAddress(Address address){
        if(buyersService.findById(address.getBuyerId())!=null){
            address.setAddressId(UUIdUtil.getUserId());
            return addressMapper.add(address);
        }
        return false;

    }
    @Schema(description = "删除地址信息")
    public boolean deleteAddress(String addressId){
        return addressMapper.delete(addressId);
    }
    @Schema(description = "更新地址信息")
    public boolean updateAddress(Address address){
        return addressMapper.update(address);
    }
    @Schema(description = "根据地址id查询地址信息")
    public Address findById(String addressId){
        return addressMapper.findById(addressId);
    }

    @Schema(description = "根据用户id查询所有地址信息")
    public ArrayList<Address> findByUserId(String userId){
        return addressMapper.findByUserId(userId);
    }

    @Schema(description = "根据用户id删除所有地址信息")
    public boolean deleteByUserId(String userId){
        return addressMapper.deleteByUserId(userId);
    }
}
